<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="pt" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:sec="http://www.springframework.org/security/facelets/tags"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/templates/admin/home-admin.xhtml">
	<ui:define name="corpo">
		<div align="left">
			<h:panelGrid columns="1">
				<h:form id="formCad">

					<p:panel toggleable="true" header="Pesquisar Estabelecimento"
						style="width: 1025px;">
						<table>
							<tr>
								<td><p:panelGrid columns="2">
										<h:outputLabel value="Nome: " />
										<p:inputText value="#{estabelecimentoMB.campoPesquisa}"
											required="true"
											requiredMessage="Parâmetro inválido. Por favor, informe um nome de estabelecimento válido." />
									</p:panelGrid></td>
								<td><p:commandButton value="Pesquisar"
										title="Pesquisar estabelecimento no sistema, informe o nome ou parte do nome."
										action="#{estabelecimentoMB.pesquisar}" ajax="false" /></td>

							</tr>
						</table>
						<p:spacer />

					</p:panel>
				</h:form>
				<h:form>
					<p:commandButton value="Voltar" action="home-admin.jsf"
						ajax="false" title="Voltar para  a tela inicial do sistema" />
				</h:form>
				<h:form prependId="false">
					<p:panel
						rendered="#{estabelecimentoMB.entity.id==0 and not empty estabelecimentoMB.campoPesquisa }">
						<p:dataTable value="#{estabelecimentoMB.estabelecimentos}"
							var="ests" emptyMessage="Nenhum resultado.">
							<p:column headerText="Nome">
								<h:outputText value="#{ests.nome}" />
							</p:column>

							<p:column headerText="CNPJ">
								<h:outputText value="#{ests.cnpj}" />
							</p:column>
							<p:column headerText="Ação">
								<p:commandLink ajax="false"
									action="#{estabelecimentoMB.editarAdmin}">
									<f:setPropertyActionListener
										target="#{estabelecimentoMB.entity}" value="#{ests}" />
									<p:graphicImage
										value="#{pageContext.servletContext.contextPath}/images/botao_consultar.jpg"
										title="Consultar" />
								</p:commandLink>

								<p:commandLink ajax="false"
									action="#{estabelecimentoMB.desabilitarEstabelecimento}"
									onclick="javascript:msg();">
									<f:setPropertyActionListener
										target="#{estabelecimentoMB.entity}" value="#{ests}" />
									<p:graphicImage
										value="#{pageContext.servletContext.contextPath}/images/excluir-m.gif"
										title="Desabilitar" />
								</p:commandLink>


							</p:column>
						</p:dataTable>



					</p:panel>

				</h:form>

			</h:panelGrid>

			<h:form prependId="false"> 
				<p:commandButton id="showDialogButton" value="Desabilitar registro"
					onclick="confirmation.show()" type="button" />


				<p:confirmDialog id="confirmDialog"
					message="Are you sure about destroying the world?"
					header="Initiating destroy process" severity="alert"
					widgetVar="confirmation">
					<p:commandButton id="confirm" value="OK"
						oncomplete="confirmation.hide()"
						actionListener="#{estabelecimentoMB.desabilitarEstabelecimento}" />
					<p:commandButton id="decline" value="Cancelar"
						onclick="confirmation.hide()" type="button" />
				</p:confirmDialog>

			</h:form>



			<h:form>
				<p:panel rendered="#{estabelecimentoMB.apresentaTelaCadastro}">
					<ui:include src="tela-cadastro-administrador.xhtml"></ui:include>

				</p:panel>
			</h:form>


		</div>



		<script type="text/javascript">
				function msg(){
					confirm("Tem certeza que deseja desabalitar o cadastro do estabelecimento ?");
				}
		</script>


	</ui:define>
</ui:composition>
</html>